home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / www / amitrix / httx17.lha / HTTX / HTTXPluginPRT.awebrx < prev    next >
Text File  |  1998-03-07  |  4KB  |  243 lines

  1. /*
  2.     Print current document as TEXT using HTTX
  3.     $VER: HTTXPluginPRT 2.1 (23.1.98) by Gabriele Favrin (favrin@tin.it)
  4. */
  5.  
  6. options results
  7. options Failat 999
  8.  
  9. parse ARG mode mode_data .
  10. parse SOURCE . . . resolved .
  11.  
  12. plugin_path = FindPath(resolved)
  13.  
  14. 'GetCFG TEMPPATH VAR' prefs_temppath
  15. If Right(prefs_temppath, 1) ~= "/" & Right(prefs_temppath, 1) ~= ":" then do
  16.     prefs_temppath=prefs_temppath"/"
  17. End
  18.  
  19. req_title = '"Print as text"'
  20. temp_out     = prefs_temppath"temp_HTTXP_Output.txt"
  21. temp_name = prefs_temppath"temp_HTTXP_file"
  22. temp_inc  = prefs_temppath"temp_HTTXP_header"
  23. del_list     = prefs_temppath"temp_HTTXP_#?"
  24. eol         = '0A'x
  25. trg         = ""
  26. force         = ""
  27. string     = ""
  28. option     = ""
  29. append     = ""
  30. converted = 0
  31.  
  32. prefs_info     = 0
  33. prefs_report = 1
  34. prefs_save_noheader=0
  35. prefs_print_noheader=0
  36.  
  37. Call ReadCfg()
  38.  
  39. If (mode == "TARGET") then do
  40.     trg="TARGET" mode_data
  41. End
  42.  
  43. 'Get URL VAR' doc_url trg
  44. 'Get TITLE VAR' doc_title trg
  45.  
  46. 'GetCFG FRAMES'
  47. If result == 0 then do
  48.     frms.0=0
  49. End
  50. else do
  51.     'Get FRAMES ALL' trg 'STEM' frms
  52. End
  53.  
  54. If (frms.0 = 0) then do
  55.     Call SaveHTML()
  56.     Call Convert()
  57.     Call CleanUp()
  58. End
  59. else do
  60.     prefs_report=0
  61.  
  62.     'Request' req_title '"Selected document contains frames." "Convert _All|_Select frame(s)|_Cancel"'
  63.     If rc == 5 then exit 0
  64.     option=result
  65.  
  66.     do ct=0 for (frms.0)+1
  67.         If ct > 0 then do
  68.             doc_url=frms.ct.url
  69.             doc_title=frms.ct.name
  70.             trg="TARGET="frms.ct.id
  71.         End
  72.  
  73.         If option == 1 then do
  74.             'Get FRAMESET' trg
  75.             If (result == 0) then do
  76.                 If converted then do
  77.                     drop append
  78.                     string=eol||"----"||eol
  79.                 End
  80.  
  81.                 Call SaveHTML()
  82.                 Call Convert()
  83.                 Call CleanUp()
  84.             End
  85.         End
  86.         else do
  87.             'Open "'doc_url'"'
  88.             'Wait "'doc_url'"'
  89.  
  90.             'Get FRAMESET'
  91.             If (result == 0) then do
  92.                 'Request' req_title '"Convert this frame?" "_Yes|_No|_Cancel"'
  93.                 If (rc == 5) then do
  94.                     Call CleanUp()
  95.                     If (ct > 0) then do
  96.                         'GO' ct 'BACK'
  97.                     End
  98.                     exit 0
  99.                 End
  100.  
  101.                 If result == 1 then do
  102.                     trg=""
  103.                     string=""
  104.                     Call SaveHTML()
  105.                     Call Convert()
  106.                     Call CleanUp()
  107.                 End
  108.             End
  109.         End
  110.     End
  111.  
  112.     If option == 1 then do
  113.         Call displayOutput()
  114.         Call CleanUp()
  115.     End
  116.     else do
  117.         If (option == 2) & (ct > 0) then do
  118.             'GO' ct 'BACK'
  119.         End
  120.         Call CleanUp()
  121.     End
  122. End
  123.  
  124. exit 0
  125.  
  126.  
  127. CleanUp:
  128.     /*address command 'C:Delete >NIL: QUIET' del_list*/
  129.     return
  130.  
  131.  
  132. SaveHTML:
  133.     'SaveAs "'temp_name'" NOICON' trg
  134.     If (rc ~= 0) then do
  135.         'Request 'req_title' "Error while saving HTML on temporary path*N *N'prefs_temppath'" "_Ok" NOWAIT'
  136.         exit 0
  137.     End
  138.     return
  139.  
  140.  
  141. Convert:
  142.     'Get MIME VAR' mtype trg
  143.     If (Upper(mtype) == "TEXT/HTML") then do
  144.         drop force
  145.     End
  146.     else do
  147.         force=""
  148.     End
  149.  
  150.     Call PrepareFile()
  151.  
  152.     res=httx()
  153.     If (res == 212) then do
  154.         'Request 'req_title' "File is not HTML! Print anyway?" "_Print|_Cancel"'
  155.  
  156.         If (rc ~= 5) then do
  157.             address command 'C:Copy "'temp_name'" "PRT:"'
  158.             prefs_report=0
  159.             res=0
  160.             Call displayOutput()
  161.         End
  162.     End
  163.     else do
  164.         If option == "" then do
  165.             Call displayOutput()
  166.         End
  167.     End
  168.     converted=1
  169.     return
  170.  
  171.  
  172. httx:
  173.     address command '"'plugin_path'HTTX" >'temp_out' "'temp_name'" PRINT NOHEADER CFG=HTTXprt.prefs INCLUDE="'temp_inc'"' force append
  174.     return rc
  175.  
  176.  
  177. DisplayOutput:
  178.     If (prefs_report == 1) then do
  179.         'Open "file:///'temp_out'" RELOAD'
  180.         'Wait "file:///'temp_out'"'
  181.     End
  182.     else do
  183.         If (res == 0) then do
  184.             'Request 'req_title' "File printed" "_Ok" NOWAIT'
  185.         End
  186.         else do
  187.             'Request 'req_title' "Error 'rc'" "_Ok" NOWAIT'
  188.         End
  189.     End
  190.     return
  191.  
  192.  
  193. PrepareFile:
  194.     If Open(fp, temp_inc, 'W') then do
  195.         If (prefs_save_noheader == 0) then do
  196.             If (prefs_info == 1) then do
  197.                 'Get INFO STEM' infos trg
  198.                 If (infos.0 > 0) then do
  199.                     string=string||eol||"Header:"||eol
  200.  
  201.                     do ctx=1 for infos.0
  202.                         If (infos.ctx.type ~= "CACHE") then do
  203.                             string=string||infos.ctx.value||eol
  204.                             If infos.ctx.type == "LINK" then string=string||eol||infos.ctx.url
  205.                         End
  206.                     End
  207.                 End
  208.             End
  209.  
  210.             string=string||eol||'URL  : 'doc_url||eol'Title: 'doc_title
  211.         End
  212.  
  213.         WriteCH(fp, string)
  214.         Call Close(fp)
  215.     End
  216.     return
  217.  
  218.  
  219. ReadCfg:
  220.     If Open(rcfg_fp, 'ENV:HTTXPlugin.config', 'R') then do
  221.         cfg=ReadLN(rcfg_fp)
  222.  
  223.         If Left(cfg, 6) == "prefs_" then do
  224.             interpret translate(strip(cfg), ';',' ')
  225.             prefs_savedir=Translate(prefs_savedir, ' ', ';')
  226.         End
  227.  
  228.         Call Close(rcfg_fp)
  229.     End
  230.  
  231.  
  232. FindPath:
  233.     procedure
  234.  
  235.     parse ARG pathf
  236.     dir_pos=Max(lastpos('/', pathf), lastpos(':', pathf))
  237.     If dir_pos > 0    then do
  238.         return(left(pathf,dir_pos))
  239.     End
  240.     else do
  241.         return('')
  242.     End
  243.